#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-

# @Time    :2023/05/01 13:25:53
# @Author  :wakeblade (2390245#qq.com) 
# @version :8.1

"""
constants.py -- X2Trade用到的一些常量
"""

from enum import Enum

# 交易刻度
class Interval(Enum):

    TICK = "tick"
    MINUTE = "min"
    HOUR = "h"
    DAILY = "d"
    WEEKLY = "w"
    MONTHLY = "mon"
    QUARTERLY = "q"
    HALFLY = "half"
    ANNUALLY = "a"

Interval2Mins = dict(
    tick = 0,
    min = 1,
    h = 60,
    d = 60*6,
    w = 60*6*5,
    mon = 60*6*23,
    q = 60*6*23*3,
    half = 60*6*23*6,
    a = 60*6*252
)

def parseFreq(freq:str) ->tuple:
    freq = freq.lower()
    for i in range(len(freq)):
        if freq[i].isalpha():
            break
        
    if i<1:
        return 1, freq
    
    return int(freq[:i]), freq[i:]

def freq2mins(freq:str) ->int:
    i, s = parseFreq(freq)
    return i * Interval2Mins[s] 

# 交易所
class Exchange(Enum):

    # 国内
    CFFEX = "CFFEX"         # China Financial Futures Exchange
    SHFE = "SHFE"           # Shanghai Futures Exchange
    CZCE = "CZCE"           # Zhengzhou Commodity Exchange
    DCE = "DCE"             # Dalian Commodity Exchange
    INE = "INE"             # Shanghai International Energy Exchange
    GFEX = "GFEX"           # Guangzhou Futures Exchange
    SSE = "SSE"             # Shanghai Stock Exchange
    SZSE = "SZSE"           # Shenzhen Stock Exchange
    BSE = "BSE"             # Beijing Stock Exchange
    SGE = "SGE"             # Shanghai Gold Exchange
    WXE = "WXE"             # Wuxi Steel Exchange
    CFETS = "CFETS"         # CFETS Bond Market Maker Trading System
    XBOND = "XBOND"         # CFETS X-Bond Anonymous Trading System

    # 全球
    SMART = "SMART"         # Smart Router for US stocks
    NYSE = "NYSE"           # New York Stock Exchnage
    NASDAQ = "NASDAQ"       # Nasdaq Exchange
    ARCA = "ARCA"           # ARCA Exchange
    EDGEA = "EDGEA"         # Direct Edge Exchange
    ISLAND = "ISLAND"       # Nasdaq Island ECN
    BATS = "BATS"           # Bats Global Markets
    IEX = "IEX"             # The Investors Exchange
    AMEX = "AMEX"           # American Stock Exchange
    TSE = "TSE"             # Toronto Stock Exchange
    NYMEX = "NYMEX"         # New York Mercantile Exchange
    COMEX = "COMEX"         # COMEX of CME
    GLOBEX = "GLOBEX"       # Globex of CME
    IDEALPRO = "IDEALPRO"   # Forex ECN of Interactive Brokers
    CME = "CME"             # Chicago Mercantile Exchange
    ICE = "ICE"             # Intercontinental Exchange
    SEHK = "SEHK"           # Stock Exchange of Hong Kong
    HKFE = "HKFE"           # Hong Kong Futures Exchange
    SGX = "SGX"             # Singapore Global Exchange
    CBOT = "CBT"            # Chicago Board of Trade
    CBOE = "CBOE"           # Chicago Board Options Exchange
    CFE = "CFE"             # CBOE Futures Exchange
    DME = "DME"             # Dubai Mercantile Exchange
    EUREX = "EUX"           # Eurex Exchange
    APEX = "APEX"           # Asia Pacific Exchange
    LME = "LME"             # London Metal Exchange
    BMD = "BMD"             # Bursa Malaysia Derivatives
    TOCOM = "TOCOM"         # Tokyo Commodity Exchange
    EUNX = "EUNX"           # Euronext Exchange
    KRX = "KRX"             # Korean Exchange
    OTC = "OTC"             # OTC Product (Forex/CFD/Pink Sheet Equity)
    IBKRATS = "IBKRATS"     # Paper Trading Exchange of IB

    # Special Function
    LOCAL = "LOCAL"         # For local generated data

# 代码转英文
class Exchange2en(Enum):

    # 国内
    CFFEX = "China Financial Futures Exchange"
    SHFE = "Shanghai Futures Exchange"
    CZCE = "Zhengzhou Commodity Exchange"
    DCE = "Dalian Commodity Exchange"
    INE = "Shanghai International Energy Exchange"
    GFEX = "Guangzhou Futures Exchange"
    SSE = "Shanghai Stock Exchange"
    SZSE = "Shenzhen Stock Exchange"
    BSE = "Beijing Stock Exchange"
    SGE = "Shanghai Gold Exchange"
    WXE = "Wuxi Steel Exchange"
    CFETS = "CFETS Bond Market Maker Trading System"
    XBOND = "CFETS X-Bond Anonymous Trading System"

    # 国际
    SMART = "Smart Router for US stocks"
    NYSE = "New York Stock Exchnage"
    NASDAQ = "Nasdaq Exchange"
    ARCA = "ARCA Exchange"
    EDGEA = "Direct Edge Exchange"
    ISLAND = "Nasdaq Island ECN"
    BATS = "Bats Global Markets"
    IEX = "The Investors Exchange"
    AMEX = "American Stock Exchange"
    TSE = "Toronto Stock Exchange"
    NYMEX = "New York Mercantile Exchange"
    COMEX = "COMEX of CME"
    GLOBEX = "Globex of CME"
    IDEALPRO = "Forex ECN of Interactive Brokers"
    CME = "Chicago Mercantile Exchange"
    ICE = "Intercontinental Exchange"
    SEHK = "Stock Exchange of Hong Kong"
    HKFE = "Hong Kong Futures Exchange"
    SGX = "Singapore Global Exchange"
    CBOT = "Chicago Board of Trade"
    CBOE = "Chicago Board Options Exchange"
    CFE = "CBOE Futures Exchange"
    DME = "Dubai Mercantile Exchange"
    EUREX = "Eurex Exchange"
    APEX = "Asia Pacific Exchange"
    LME = "London Metal Exchange"
    BMD = "Bursa Malaysia Derivatives"
    TOCOM = "Tokyo Commodity Exchange"
    EUNX = "Euronext Exchange"
    KRX = "Korean Exchange"
    OTC = "OTC Product (Forex/CFD/Pink Sheet Equity)"
    IBKRATS = "Paper Trading Exchange of IB"

    # Special Function
    LOCAL = "LOCAL"         # For local generated data

# 代码转中文
class Exchange2cn(Enum):

    # 国内
    CFFEX = "中国金融期货交易所"
    SHFE = "上海期货交易所"
    CZCE = "郑州商品交易所"
    DCE = "大连商品交易所"
    INE = "上海能源交易所"
    GFEX = "广州期货交易所"
    SSE = "上海证券交易所"
    SZSE = "深圳证券交易所"
    BSE = "北京证券交易所"
    SGE = "上海黄金交易所"
    WXE = "无锡钢铁交易所"
    CFETS = "CFETS Bond Market Maker Trading System"
    XBOND = "CFETS X-Bond Anonymous Trading System"

    # Global
    SMART = "Smart Router for US stocks"
    NYSE = "纽约股票交易所"
    NASDAQ = "纳斯达克"
    ARCA = "ARCA Exchange"
    EDGEA = "Direct Edge Exchange"
    ISLAND = "Nasdaq Island ECN"
    BATS = "Bats Global Markets"
    IEX = "The Investors Exchange"
    AMEX = "American Stock Exchange"
    TSE = "东京证券交易所"
    NYMEX = "New York Mercantile Exchange"
    COMEX = "COMEX of CME"
    GLOBEX = "Globex of CME"
    IDEALPRO = "Forex ECN of Interactive Brokers"
    CME = "Chicago Mercantile Exchange"
    ICE = "Intercontinental Exchange"
    SEHK = "香港证券交易所"
    HKFE = "香港期货交易所"
    SGX = "Singapore Global Exchange"
    CBOT = "Chicago Board of Trade"
    CBOE = "Chicago Board Options Exchange"
    CFE = "CBOE Futures Exchange"
    DME = "Dubai Mercantile Exchange"
    EUREX = "Eurex Exchange"
    APEX = "亚太交易所"
    LME = "伦敦金属交易所"
    BMD = "Bursa Malaysia Derivatives"
    TOCOM = "Tokyo Commodity Exchange"
    EUNX = "Euronext Exchange"
    KRX = "韩国交易所"
    OTC = "OTC Product (Forex/CFD/Pink Sheet Equity)"
    IBKRATS = "Paper Trading Exchange of IB"

    # Special Function
    LOCAL = "LOCAL"         # For local generated data
